SHELL=bash

include config.mk

CLEAN_OBJS=*.o
REALCLEAN_OBJS=

HADOOP_LIB_PATH=$(HADOOP_PATH)/lib

EXT=
V8LIBPATH=ext/v8/libv8.a
V8INCLUDEPATH=ext/v8/include

CFLAGS=\
  -m32 \
  -pedantic \
  -Wall \
  -g 

CCFLAGS=\
  -m32 \
  -pedantic \
  -Wall \
  -g  \
  -I$(V8INCLUDEPATH) \
  -I$(HADOOP_PATH)/include \
  -lpthread

LDFLAGS= -L$(HADOOP_LIB_PATH) 

LIBTOOL = ext/libcurl/libtool
CURLLIBDIR = ext/libcurl/lib
CURLH=ext/libcurl/include
LINK=$(LIBTOOL) --tag=CC --mode=link g++ $(CFLAGS) $(LDFLAGS) -o $@


JNI_H=ext/$(JDKPATH)/include/
JNI_MD_H=ext/$(JDKPATH)/include/linux/
LIBHDFS_LIBS+=\
ext/$(JDKPATH)/jre/lib/i386/client/libjvm.so \
ext/$(JDKPATH)/jre/lib/i386/libjava.so \
ext/$(JDKPATH)/jre/lib/i386/libverify.so \

hadoop_ld=\
  $(HADOOP_LIB_PATH)/libhadooppipes.a \
  $(HADOOP_LIB_PATH)/libhadooputils.a \
  $(LIBHDFS_LIBS) \
  $(V8LIBPATH) \
  $(CURLLIBDIR)/libcurl.la

hadoop_libs=\
  -I$(LIBHDFS) \
  -I$(JNI_MD_H) \
  -I$(JNI_H) \
  -I$(CURLH) \
  -I$(V8INCLUDEPATH)

###############################################################################

default: external hadoop_jsmr_container 

all: external hadoop_jsmr_container test_container

include external.mk

external: $(EXT)

jsmr.o: jsmr.cc jsmr.h 
	g++ $(CCFLAGS) -c -o $@ $<

hadoop_jsmr_container.o: hadoop_jsmr_container.cc  
	g++ -c -o $@ $< $(CCFLAGS) $(hadoop_libs) 
CLEAN_OBJS+=hadoop_jsmr_container.o

hadoop_jsmr_container: hadoop_jsmr_container.o jsmr.o ext/urlparser/urlparser.o ext/v8/libv8.a 
	$(LINK)  hadoop_jsmr_container.o $(hadoop_libs) $(hadoop_ld) jsmr.o ext/urlparser/urlparser.o
CLEAN_OBJS+=hadoop_jsmr_container
CLEAN_OBJS+=.libs/hadoop_jsmr_container

docs:
	rm -rf html latex
	doxygen Doxyfile
CLEAN_OBJS+=html
CLEAN_OBJS+=latex

test:
	pushd tests; \
	make;
	
clean:
	rm -rf $(CLEAN_OBJS); \
	pushd tests; \
	make clean

realclean: clean
	rm -rf $(REALCLEAN_OBJS)
